package update

import (
	"log"
	"time"

	"gitee.com/dark.H/go-utils/s"
)

type Updater interface {
	CheckUpdate() bool
	DownUpdate() (string, error)
	CheckUpdateIfSuccess() bool
}

func UpdateCheck(updater Updater, intervalMinute int) {
	ticker := time.NewTicker(time.Duration(intervalMinute) * time.Minute)
	for {
		select {
		case <-ticker.C:
			if updater.CheckUpdate() {
				if downPath, err := updater.DownUpdate(); err != nil {
					log.Println("update failed:", err)
				} else {

					s.Str()
				}

			}
		default:
			time.Sleep(1 * time.Minute)
		}
	}
}
